// pages/workTable/index.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user_type: '1',//1学生 2教师
    rws: [], // 我的任务
    tasks:[
      {
        name: '阅读任务',
        url: '/pages/task/publishtask/publishtask',
        image: '../../images/workTable/fmStuRead.png', //阅读任务
        baColor: '#2979ff',
        openType: 'navigate'
      },
      {
        name: '亲子共读',
        url: '/pages/readWorks/addWork/index?tasktype=0',
        image: '../../images/workTable/readTask.png', //亲子共读
        baColor: '#ff9900',
        openType: 'navigate'
      },
      {
        name: '师生共读',
        url: '/pages/readWorks/addWork/index?tasktype=1',
        image: '../../images/workTable/teaStuRead.png', //师生共读
        baColor: '#19be6b',
        openType: 'navigate'
      }
    ],

    mywork:[
      {
        name: '发布作品',
        url: '/pages/fbzp/fbzp',
        image: '../../images/workTable/Creation.png', //我要创作
        baColor: '#2979ff',
        openType: 'navigate'
      },
      {
        name: '推荐书籍',
        url: '/pages/booktj/booktj',
        image: '../../images/workTable/recomendBook.png', //我要推荐
        baColor: '#ff9900',
        openType: 'navigate'
      },
      {
        name: '背诵任务',
        url: '/pages/task/mytask/mytask',
        image: '../../images/workTable/myTask.png', //背诵任务
        baColor: '#19be6b',
        openType: 'switchTab'
      },
      {
        name: '阅读任务',
        url: '/pages/readWorks/listWorks/index',
        image: '../../images/workTable/readWorks.png', //阅读任务
        baColor: '#ff9900',
        openType: 'navigate'
      }
    ],

    bookshelves: [
      {
        name: '正在阅读',
        url: '/pages/wdsj/wdsj',
        image: '../../images/workTable/readingBook.png', //正在阅读
        baColor: '#ff9900',
        openType: 'switchTab'
      },
      {
        name: '历史阅读',
        url: '/pages/wdsj/wdsj',
        image: '../../images/workTable/HistoryRead.png', //历史阅读
        baColor: '#2979ff',
        openType: 'switchTab'
      },
      {
        name: '我的收藏',
        url: '/pages/wdsj/wdsj',
        image: '../../images/workTable/collectionBook.png', //我的收藏
        baColor: '#19be6b',
        openType: 'switchTab'
      },
      {
        name: '我的作品',
        url: '/pages/xsyc/xsyc',
        image: '../../images/workTable/myWorks.png', //我的作品
        baColor: '#ff9900',
        openType: 'navigate'
      },
      {
        name: '教师推荐',
        url: '/pages/hxtj/hxtj?tjly=0',
        image: '../../images/workTable/teaTJ.png', //教师推荐
        baColor: '#2979ff',
        openType: 'navigate'
      },
      {
        name: '家长推荐',
        url: '/pages/hxtj/hxtj?tjly=1',
        image: '../../images/workTable/famTJ.png', //家长推荐
        baColor: '#19be6b',
        openType: 'navigate'
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var user_type = wx.getStorageSync('user_type');
    if (!user_type){
      wx.redirectTo({
        url: '../../login/login'
      })
    }else{
      this.setData({
        user_type: user_type
      })
      if(user_type == '1'){
        this.getMytask()
      }
    }
    
  },

  getMytask: function (e) {
    var that = this;
    var usid = wx.getStorageSync('usid');
    var nj = wx.getStorageSync('nj');
    var bj = wx.getStorageSync('bj');
    app.wxget({
      url: 'poetryread/poetryreadWwc.html',
      data: {
        usid: usid,
        nj: nj,
        bj: bj
      },
      success: function (res) {
        var datas = res.data;
        that.setData({
          rws: datas
        })
      }
    })
  },

  toTaskDetail(e){
      var readid = e.currentTarget.dataset.readid
      wx.navigateTo({
        url: '../../pages/task/poetryDetail/poetryDetail?readid=' + readid
      })
  }

})